package main

func main() {

	//root = [4,2,9,3,5,null,7]
	node3 := TreeNode{
		Val:   3,
		Left:  nil,
		Right: nil,
	}
	node4 := TreeNode{
		Val:   5,
		Left:  nil,
		Right: nil,
	}
	node5 := TreeNode{
		Val:   7,
		Left:  nil,
		Right: nil,
	}
	node1 := TreeNode{
		Val:   2,
		Left:  &node3,
		Right: &node4,
	}
	node2 := TreeNode{
		Val:   9,
		Left:  nil,
		Right: &node5,
	}
	root := TreeNode{
		Val:   4,
		Left:  &node1,
		Right: &node2,
	}

	//ROOT2
	node33 := TreeNode{
		Val:   3,
		Left:  nil,
		Right: nil,
	}
	node44 := TreeNode{
		Val:   5,
		Left:  nil,
		Right: nil,
	}
	node55 := TreeNode{
		Val:   7,
		Left:  nil,
		Right: nil,
	}
	node11 := TreeNode{
		Val:   2,
		Left:  &node33,
		Right: &node44,
	}
	node22 := TreeNode{
		Val:   9,
		Left:  nil,
		Right: &node55,
	}
	root1 := TreeNode{
		Val:   4,
		Left:  &node11,
		Right: &node22,
	}

	//打印测试用例返回结果
	resp := isSameTree(&root, &root1)
	println(resp)

}

//Definition for a binary tree node.
type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

type Queue struct {
	Val  int
	Next *Queue
}

/*
给你两棵二叉树的根节点 p 和 q ，编写一个函数来检验这两棵树是否相同。
如果两个树在结构上相同，并且节点具有相同的值，则认为它们是相同的。
*/
func isSameTree(p *TreeNode, q *TreeNode) bool {

	//p和q只有其中一个为空，返回false
	if p != nil && q == nil || p == nil && q != nil {
		return false
	}
	if p == nil && q == nil {
		return true
	}
	if p.Val != q.Val {
		return false
	}
	if !isSameTree(p.Left, q.Left) {
		return false
	}
	if !isSameTree(p.Right, q.Right) {
		return false
	}
	return true
}

//使用队列层序遍历
